#ifndef _FLASH_DATA_H_
#define _FLASH_DATA_H_

#include "pstorage.h"
#include <stdbool.h>
#include "app_scheduler.h"

struct flash_parm_t
{
    uint8_t num;
    uint8_t *buf;
    uint16_t length;
    uint16_t offset;
};

typedef enum {
    FLASH_STATUS_WRITE_START,
    FLASH_STATUS_WRITE_END,
    FLASH_STATUS_READ_START,
    FLASH_STATUS_READ_END,
}FLASH_STATUS;

// 根据CONFIG_AUDIO_FRAME_SIZE_SAMPLES配置，方便写入
#define FLASH_DATA_BLOCK_SIZE        512
#define FLASH_DATA_BLOCK_NUM         70

typedef void (*flash_status_cb)(FLASH_STATUS status);
typedef void (*flash_data_pdm_eraser_finish_fun_t)(uint8_t num);

#if defined (__CC_ARM )
#define ADDR_ALIGNED_4 __attribute__ ((aligned (4)))
#endif

extern uint32_t flash_data_init(bool is_init_pstorage);
extern uint32_t flash_data_write(uint32_t block_num,uint8_t *buf,uint32_t length,uint32_t offset);
extern uint32_t flash_data_read(uint32_t block_num,uint8_t *buf,uint32_t length,uint32_t offset);
extern void flash_data_get_err_info(uint16_t *read_err,uint16_t *write_err);
extern uint32_t flash_data_status_evt_reg(flash_status_cb func);
extern uint32_t flash_data_clear(uint32_t block_num,uint32_t block_cnt);
extern uint32_t flash_data_store(uint32_t block_num,uint8_t *buf,uint32_t length,uint32_t offset);
extern uint32_t flash_data_get_startADD(void);
extern bool flash_data_pdm_eraser_finish_reg(flash_data_pdm_eraser_finish_fun_t fun);

#endif
